第 13 步:我们的 while 循环现在已经设置好了,但是我们如何知道一行代码是否会导致错误呢?

如果try下的代码失败, try-except 块可以防止程序崩溃。如果try下面缩进的代码提示错误,则except下面的代码运行。

  • ,将Try Generic Exception拖到 while 循环handle_user_errors()中。
  • 点击运行控制台。除以零会导致错误,因此改为运行print命令!

To navigate the page using the TAB key, first press ESC to exit the code editor.

# THIS ACTIVITY IS IN PREVIEW ONLY MODE
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)